package com.caesar.exer1;

/**
 * @author caesar
 * @date 2025/7/21
 * @Description:
 * @apiNote
 */
public class Testexer1 {
    public static void main(String[] args) throws InterruptedException {
        // 共享计数器
        Counter counter = new Counter();

        // 线程数量和每个线程递增次数
        int threadCount = 10;
        int iterationsPerThread = 1000;

        // 创建并启动线程
        Thread[] threads = new Thread[threadCount];
        for (int i = 0; i < threadCount; i++) {
            threads[i] = new CounterThread(counter, iterationsPerThread);
            threads[i].start();
        }

        // 等待所有线程执行完成
        for (Thread thread : threads) {
            thread.join();
        }

        // 验证最终结果
        System.out.println("最终计数器值: " + counter.getCount());
        int expectedCount = threadCount * iterationsPerThread;
        System.out.println("预期值: " + expectedCount);
        System.out.println("结果是否正确: " + (counter.getCount() == expectedCount ? "是" : "否"));
    }
}
